package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.BigCustomer;
import cn.wolfcode.edu.query.BigCustomerQueryObject;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IBigCustomerService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by NEUZJ on 2018/7/9.
 */
@Controller
@RequestMapping("/bigcustomer")
public class BigCustomerContoller {
    @Autowired 
    private IBigCustomerService bigCustomerService;
   
    @RequestMapping("")
    public String index() {
        return "bigcustomer";
    }
    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(BigCustomerQueryObject qo) {
        return bigCustomerService.query(qo);
    }
    //保存大客户
    @RequestMapping("/save")
    @ResponseBody
    public JsonResult save(BigCustomer bigCustomer) {
        JsonResult jsonResult=new JsonResult();
        try {
            bigCustomerService.save(bigCustomer);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.remark("出事了");
            return jsonResult;
        }
        return jsonResult;

    }
    //更新大客户
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult udpate(BigCustomer bigCustomer) {
        JsonResult jsonResult=new JsonResult();
        try {
            bigCustomerService.update(bigCustomer);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.remark("出事了");
            return jsonResult;
        }
        return jsonResult;

    }
    //删除大客户
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        try {
            bigCustomerService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.remark("出事了");
            return jsonResult;
        }
        return jsonResult;

    }
    //和大客户签约
    @RequestMapping("/sign")
    @ResponseBody
    public JsonResult sign(Long id,Integer flag) {
        JsonResult jsonResult = new JsonResult();
        try {
            System.out.print("********************************");
            bigCustomerService.sign(id,flag);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.remark("出事了");
            return jsonResult;
        }
        return jsonResult;
    }


    //陈遵汉 专属
    //查询所有的大客户的信息 以集合的json形式放回
    @RequestMapping("listAll")
    @ResponseBody
    public List<BigCustomer> listAll() {
        List<BigCustomer> bigCustomers = bigCustomerService.listAll();
        return bigCustomers;
    }
    //陈遵汉 专属
}
